import { Settings } from 'meilisearch'

export const defaultMeiliSettings: Settings = {
  searchableAttributes: [],
  pagination: {
    maxTotalHits: 100000,
  },
}

const defaultResourceDisplayedAttributes = [
  'id',
  'name',
  'shortDescription',
  'invite',
  'avatar',
  'premiumActive',
  'rating',
  'banner',
  'tags',
]

const defaultRankingRules = [
  'words',
  'typo',
  'proximity',
  'attribute',
  'sort',
  'exactness',
]

export const serversMeiliSettings: Settings = {
  ...defaultMeiliSettings,
  searchableAttributes: [ 'description', 'shortDescription', 'name' ],
  rankingRules: [
    ...defaultRankingRules,
    'name:desc',
    'shortDescription:desc',
    'description:desc',
    'reviews:desc',
  ],
  filterableAttributes: [ 'members', 'tags' ],
  sortableAttributes: [ 'members', 'rating', 'ups', 'created', 'reviews' ],
  displayedAttributes: [
    ...defaultResourceDisplayedAttributes,
    'members',
    'discordBanner',
  ],
}

export const botsMeiliSettings: Settings = {
  ...defaultMeiliSettings,
  searchableAttributes: [ 'description', 'shortDescription', 'name' ],
  rankingRules: [
    ...defaultRankingRules,
    'name:desc',
    'shortDescription:desc',
    'description:desc',
    'reviews:desc',
  ],
  filterableAttributes: [ 'guilds', 'tags' ],
  sortableAttributes: [ 'guilds', 'rating', 'ups', 'created', 'reviews' ],
  displayedAttributes: [
    ...defaultResourceDisplayedAttributes,
    'guilds',
    'premiumBanner',
    'discriminator',
  ],
}

export const commentsMeiliSettings: Settings = {
  ...defaultMeiliSettings,
  rankingRules: [
    ...defaultRankingRules,
    'created:desc',
  ],
  filterableAttributes: [ 'author', 'resource' ],
  sortableAttributes: [ 'rating', 'created' ],
  displayedAttributes: [
    'id',
    'author',
    'content',
    'rating',
    'resource',
    'created',
    'modReply',
  ],
}
